package com.ebt.m.users;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ebt.m.R;
import com.ebt.m.commons.buscomponent.listview.IView;
import com.ebt.m.commons.utils.Logger;
import com.ebt.m.users.bean.CardHonour;
import com.ebt.m.users.bean.CardService;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CardHonourItemView extends IView {


    @BindView(R.id.honour_img)
    ImageView honourImg;
    @BindView(R.id.honour_title)
    TextView honourTitle;
    @BindView(R.id.honour_content)
    TextView honourContent;
    @BindView(R.id.honour_date)
    TextView honourDate;
    @BindView(R.id.action_delete)
    TextView actionDelete;
    @BindView(R.id.action_edit)
    TextView actionEdit;
    @BindView(R.id.item_root)
    RelativeLayout itemRoot;
    CardHonour cardHonour;

    public CardHonourItemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.layout_cardhonour_item, this);
        ButterKnife.bind(this);
    }

    public CardHonourItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CardHonourItemView(Context context) {
        this(context, null);
    }

    @Override
    public void update(Object... obj) {
        try {
            cardHonour = (CardHonour) obj[0];
            honourTitle.setText(cardHonour.getTitle());
            honourContent.setText(cardHonour.getDescription());
            honourDate.setText("获奖时间：" + cardHonour.getDate());
            Glide.with(getContext())
                    .load(cardHonour.getImgAddress())
                    .error(R.drawable.empty_photo)
                    .dontAnimate()
                    .into(honourImg);
        } catch (Exception e) {
            Logger.e(e);
        }

    }


    @OnClick({R.id.action_delete, R.id.action_edit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.action_delete:
                if (mOnclickListner != null)
                    mOnclickListner.onClick(view, mPosition, cardHonour);
                break;
            case R.id.action_edit:
                Intent intent = new Intent(getContext(), CardHonourEditActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("honour", cardHonour);
                intent.putExtras(bundle);
                getContext().startActivity(intent);
                break;
        }
    }
}
